package com.demo2do.fms.admin.entity.search.supplier;

import java.util.Date;
import java.util.List;
import java.util.Map;

import org.springframework.format.annotation.DateTimeFormat;

import com.demo2do.core.persistence.support.QueryBuilder;
import com.demo2do.core.persistence.support.QueryFilter;
import com.demo2do.core.persistence.support.QueryOrder;
import com.demo2do.fms.entity.driver.DriverEventType;

/**
 *
 * @author Ark
 *
 */
public class DriverEventSearch implements QueryBuilder {
    
    /** 供方id */
    private Long supplierId;
    
    /** 身份证 */
    private String citizenCode;
    
    /** 日志类型 */
    private DriverEventType type;
    
    /** 操作起始时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date startCreateTime;
    
    /** 操作结束时间 */
    @DateTimeFormat(pattern = "yyyy-MM-dd")
    private Date endCreateTime;
    
    /** 操作人 */
    private Long creator;

    private QueryOrder queryOrder;

    private QueryFilter queryFilter;

    /**
     * The default constructor
     */
    public DriverEventSearch() {
        queryOrder = new QueryOrder().add("createTime", "DESC");
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getPreparedFilter(boolean)
     */
    public QueryFilter getPreparedFilter(boolean refresh) {

        if (queryFilter == null || refresh) {

            queryFilter = new QueryFilter().addEquals("supplier.id", supplierId)
                                           .addLike("driver.citizenCode", citizenCode)
                                           .addEquals("type", type)
                                           .addDateTimeBetween("createTime", startCreateTime, endCreateTime)
                                           .addEquals("creator", creator)
                                           .addEquals("disabled", false);
        }
        
        return queryFilter;
        
    }
    
    /**
     * @param supplierIds
     */
    public void addSupplierId(List<Long> supplierIds) {
        supplierIds.add(0L);
        this.getPreparedFilter(false).addSentence("supplier.id IN (:supplierIds)", "supplierIds", supplierIds);
    }
    
    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#getOrder()
     */
    public QueryOrder getOrder() {
        return queryOrder;
    }

    /* (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildSentenceTemplate()
     */
    public String buildSentenceTemplate() {
        String sentence = " FROM DriverEvent " + getPreparedFilter(false).whereSentence() + queryOrder.sentence();
        return sentence;
    }

    /*
     * (non-Javadoc)
     * @see com.demo2do.core.persistence.support.QueryBuilder#buildParameters()
     */
    public Map<String, Object> buildParameters() {
        return getPreparedFilter(false).parameters();
    }
    
    /**
     * @return
     */
    public QueryFilter getQueryFilter(){
        return getPreparedFilter(false);
    }
    
    /**
     * @return
     */
    public Long getSupplierId() {
        return supplierId;
    }

    /**
     * @return the citizenCode
     */
    public String getCitizenCode() {
        return citizenCode;
    }
    
    /**
     * @return
     */
    public DriverEventType getType() {
        return type;
    }

    /**
     * @return the startCreateTime
     */
    public Date getStartCreateTime() {
        return startCreateTime;
    }

    /**
     * @return the endCreateTime
     */
    public Date getEndCreateTime() {
        return endCreateTime;
    }

    /**
     * @return the creator
     */
    public Long getCreator() {
        return creator;
    }

    /**
     * @param supplierId
     */
    public void setSupplierId(Long supplierId) {
        this.supplierId = supplierId;
    }
    
    /**
     * @param citizenCode the citizenCode to set
     */
    public void setCitizenCode(String citizenCode) {
        this.citizenCode = citizenCode;
    }
    
    /**
     * @param type
     */
    public void setType(DriverEventType type) {
        this.type = type;
    }

    /**
     * @param startCreateTime the startCreateTime to set
     */
    public void setStartCreateTime(Date startCreateTime) {
        this.startCreateTime = startCreateTime;
    }

    /**
     * @param endCreateTime the endCreateTime to set
     */
    public void setEndCreateTime(Date endCreateTime) {
        this.endCreateTime = endCreateTime;
    }

    /**
     * @param creator the creator to set
     */
    public void setCreator(Long creator) {
        this.creator = creator;
    }
    
}